/* 
 * File:   LiteralTerminal.h
 * Author: cpp
 *
 * Created on May 4, 2010, 3:50 AM
 */

#ifndef _LITERALTERMINAL_H
#define	_LITERALTERMINAL_H
#include "Terminal.h"

class LiteralTerminal : public Terminal {
public:
    LiteralTerminal();
    LiteralTerminal(const LiteralTerminal& orig);
    virtual ~LiteralTerminal();
    void setId(const std::string& id);
    string getSID();


private:

};

LiteralTerminal::LiteralTerminal() {
}

LiteralTerminal::LiteralTerminal(const LiteralTerminal& orig) {
    id = orig.id;
    value = orig.value;
}

LiteralTerminal::~LiteralTerminal() {
}

void LiteralTerminal::setId(const std::string& id) {
    if ((id.substr(0, 3) == "(L:") && (id[id.size() - 1] == ')'))//and
    {
        this->id = id;
    }
}

string LiteralTerminal::getSID() {
    //Converts (L:"ABC") in 'A' 'B' 'C' for parser
    //Remark: parsed result is converted to  (L:'A''B')
    //Special Cases: (L:&NUM) and (L:&STRING)
    stringstream sidstream, printstream, output;
    string sid;

    sid = this->getId();
    if (sid == "(L:&NUM)") {
        output << "NUM {printNo();}";
        return output.str();
    }
    /*
    if (sid == "(L:&STRING)") {
        output << "STRMOD {printRT(\"" << this->getId() << " = \");";
        return output.str();
    }*/

    sid = sid.substr(4, sid.size() - 6);
    printstream << "{ println(\"(L:";
    string::iterator itr;
    for (itr = sid.begin(); itr != sid.end(); ++itr) {
        sidstream << "'" << *itr << "' ";
        printstream << "'" << *itr << "'";
    }
    printstream << ")\");} ";

    stringstream a;
    output << sidstream.str() << printstream.str();

    return output.str();
}
#endif	/* _LITERALTERMINAL_H */

